import { useCallback } from 'react'
import {
  type MediaPreviewTyep,
  preview,
  MediaPreviewTyepList,
} from '@/hooks/usePreviewMedia'
import { getFileType } from '@/stores/fileStore'

export const useGlobalMethods = () => {
  const handlePreview = useCallback(
    (options: { title?: string; url: string; type: string }) => {
      let mediaType = options.type as MediaPreviewTyep
      if (MediaPreviewTyepList.indexOf(mediaType) === -1) {
        const { fileType } = getFileType(options.type)
        mediaType = fileType as MediaPreviewTyep
      }
      preview({
        title: options.title,
        type: mediaType,
        url: options.url,
      })
    },
    [],
  )

  return { handlePreview }
}
